<template>
  <!-- 工作人员 -->
  <div class="pageWrap">
    <el-form :inline="true">
      <el-form-item>
        <el-input placeholder="搜索选手姓名、手机号" v-model="name">
          <el-button slot="append" icon="el-icon-search" @click="getWP()"></el-button>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="text" icon="el-icon-plus" @click="aePerSonDialog=true">添加单条人员</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="name" label="姓名"></el-table-column>
      <el-table-column prop="phone" label="手机号"></el-table-column>
      <el-table-column prop="binding" label="绑定状态"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="{row}">
          <el-button type="text" @click="edit(row)">修改</el-button>
          <el-button type="text" @click="delBind(row)">解绑</el-button>
          <el-button type="text" @click="del(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 添加 / 修改 工作人员信息 -->
    <el-dialog
      title="添加 / 修改 工作人员信息"
      :visible.sync="aePerSonDialog"
      width="80%"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :show-close="false"
      v-if="aePerSonDialog"
    >
      <el-form label-width="80">
        <el-form-item label="姓名">
          <el-input class="iptAE" placeholder="请输入" v-model="aeForm.name" required></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input class="iptAE" placeholder="请输入" v-model="aeForm.phone" required></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="closeAEP">取 消</el-button>
        <el-button type="primary" @click="sureAEPer">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: "",
      tableData: [],
      aePerSonDialog: false,
      aeForm: { name: "", phone: "", id: 0 },
    };
  },
  methods: {
    //   查询工作人员
    getWP() {
      this.$axios
        .get(
          `/sbr/applyInfo/getMatchStaffList/${sessionStorage.getItem(
            "MandA"
          )}?name=${this.name}`
        )
        .then((res) => {
          let rr = res.data.data;
          rr.forEach((v) => {
            if (v.openId) v.binding = "已绑定";
            else v.binding = "未绑定";
          });
          this.tableData = rr;
        });
    },
    closeAEP() {
      this.aeForm = { name: "", phone: "", id: 0 };
      this.aePerSonDialog = false;
    },
    sureAEPer() {
      // console.log(this.aeForm)
      if (!this.aeForm.name || !this.aeForm.phone) {
        this.$message.error("请填写完整信息");
        return false;
      }
      this.aeForm.matchId = Number(
        this.$Base64.decode(sessionStorage.getItem("MandA"))
      );
      this.$axios
        .post("/sbr/applyInfo/putMatchStaff", this.aeForm)
        .then((res) => {
          let rr = res.data.data;
          this.getWP();
          this.aePerSonDialog = false;
          this.aeForm = { name: "", phone: "", id: 0 };
          this.$message(rr);
        });
    },
    edit(row) {
      this.aeForm.name = row.name;
      this.aeForm.phone = row.phone;
      this.aeForm.id = row.id;
      this.aePerSonDialog = true;
    },
    del(row) {
      this.$axios
        .get("/sbr/applyInfo/delMatchStaff?id=" + row.id)
        .then((res) => {
            this.$message.success('删除成功')
          this.getWP();
        });
    },
    delBind(row){
        this.$axios.get('/sbr/applyInfo/delMatchStaffOpenId?id='+row.id).then(res=>{
            this.$message.success('已解绑')
            this.getWP()
        })
    }
  },
  mounted() {
    this.getWP();
  },
};
</script>
<style scoped>
/* @import url(); 引入公共css类 */
.iptAE {
  width: 300px;
}
</style>